import {
	isEmpty
} from "@/common/comFun/utils.js";

function kanbanInit() {
	return {
		getInitByKanban: function(str, data) {
			let backData = [];


			if (str == '销售') {
				backData = kanbanInit().init_xiaoshou(data);
				// console.log(backData)
			} else if (str == '仓库') {
				backData = kanbanInit().init_cangku(data);
			} else if (str == '采购') {
				backData = kanbanInit().init_caigou(data);
			}

			return backData
		},
		init_xiaoshou: function(data) { // 销售处理

			if (!isEmpty(data)) {
				let {
					ds,
					ds1,
					ds2,
					ds3,
					ds4,
				} = data;

				let obj_ds = {
					title: '销售数量',
					oldName: '去年销售量',
					oldValue: ds[0]['OldQty'],
					newName: '今年销售量',
					newValue: ds[0]['Qty'],
				}

				let obj_ds1 = {
					title: '销售金额（万元）',
					oldName: '去年销售额',
					oldValue: ds1[0]['OldMoney'],
					newName: '今年销售额',
					newValue: ds1[0]['Money'],
				}

				let obj_ds2 = {
					title: '销售出库',
					oldName: '去年出库量',
					oldValue: ds2[0]['OldFQty'],
					newName: '今年出库量',
					newValue: ds2[0]['FQty'],
				}

				let obj_ds3 = {
					title: '回款金额（万元）',
					oldName: '去年回款',
					oldValue: ds3[0]['OldBCMoney'],
					newName: '今年回款',
					newValue: ds3[0]['BCMoney'],
				}
				let obj_ds4 = {
					title: '待收金额（万元）',
					oldName: '去年待收金额',
					oldValue: ds4[0]['OldWSKMoney'],
					newName: '今年待收金额',
					newValue: ds4[0]['WSKMoney'],
				}

				// 顶部卡片数据
				let cardDataInfo = [obj_ds, obj_ds1, obj_ds2, obj_ds3, obj_ds4];
				return cardDataInfo;
			}
		},
		init_cangku: function(data) { // 仓库处理

			if (!isEmpty(data)) {
				let {
					ds1,
					ds2,
					ds3,
					ds4,
				} = data;

				// let obj_1 = {
				// 	title: '安全库存预警',
				// 	oldName: '超过安全库存数',
				// 	oldValue: ds[0]['MAXSafeStock'],
				// 	newName: '低于安全库存数',
				// 	newValue: ds[0]['SafeStock'],
				// } 
				let obj_2 = {
					title: '期初存货数量',
					oldName: '实际值',
					oldValue: ds1[0]['FQCNum'],
					newName: '同期值',
					newValue: ds2[0]['FQCNum'],
				}
				let obj_3 = {
					title: '本期入库',
					oldName: '实际值',
					oldValue: ds3[0]['FQty'],
					newName: '同期值',
					newValue: ds3[0]['OldFQty'],
				}
				let obj_4 = {
					title: '本期出库',
					oldName: '实际值',
					oldValue: ds4[0]['FQty'],
					newName: '同期值',
					newValue: ds4[0]['OldFQty'],
				}
				let obj_5 = {
					title: '期末存货数量',
					oldName: '实际值',
					oldValue: ds1[0]['FDQNum'],
					newName: '同期值',
					newValue: ds2[0]['FDQNum'],
				}

				// 顶部卡片数据
				let cardDataInfo = [obj_2, obj_3, obj_4, obj_5];
				return cardDataInfo;
			}
		},
		init_caigou: function(data) { // 采购处理
			if (!isEmpty(data)) {

				let {
					ds,
					ds1,
					ds2,
				} = data;


				let obj_1 = {
					title: '采购申请',
					oldName: '上月申请数',
					oldValue: ds[0]['OldQty'],
					newName: '本月申请数',
					newValue: ds[0]['Qty'],
				}
				let obj_2 = {
					title: '采购订单',
					oldName: '上月采购数',
					oldValue: ds1[0]['OldQty'],
					newName: '本月采购数',
					newValue: ds1[0]['Qty'],
				}
				let obj_3 = {
					title: '采购金额(万元)',
					oldName: '上月采购额',
					oldValue: ds2[0]['OldMoney'],
					newName: '本月采购额',
					newValue: ds2[0]['Money'],
				}

				// 顶部卡片数据
				let cardDataInfo = [obj_1, obj_2, obj_3];
				return cardDataInfo;


			}
		},
	}
};
export default kanbanInit();